<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<?php 
$cat = $_POST['cat'];
$name = $_POST['name'];
$desc = mysql_real_escape_string($_POST['maincont']);
$authorised = $_POST['authorised'];
	
if(isset($_POST['saveclassifiedscat']))
{
	
	if($_GET['m']!=edit)
	{
				
		mysql_query("INSERT INTO classifieds_subcategory (`category_id`,`sub_cat_name`,`desc`, `active_status`, `created_datetime`)
												  VALUES ('$cat','$name','$desc','$authorised',
														  '".gmdate('Y-m-d H:i:s')."')");	
		//header("location: index.php?tc=addcat&_s=1");
		echo "<script>window.location='index.php?tc=classifieds_subcategory&_s=1'</script>";
	}
	
}
if(isset($_POST['updateclassifiedscat']))

{

mysql_query("UPDATE classifieds_subcategory  SET `category_id` = '$cat',`sub_cat_name`='$name',
			`desc` ='$desc',`active_status` ='$authorised',`modified_datetime`='".gmdate('Y-m-d H:i:s')."' where id='".$_POST['hid']."'")
or 
die(mysql_error());

	
	echo "<script>window.location='index.php?tc=classifieds_subcategory&_s=1'</script>";
	
}
?>

<script type="text/javascript">
function validate()
{
	if(document.up.name.value=="")
	{
		alert("Sub Category Name Missing.");	
		document.up.name.focus();
		return false;
	}
}
</script>
<?php if($_REQUEST['_s'] == 1){ ?>
    <div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;</div>
<?php } ?>
<?php 
$ssql="select * from classifieds_subcategory where id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);
if($row['active_status']=='1')
{
	
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
	
$chkdec = 'checked="checked"';
}
?>
<form name="up" action="#" method="post" onSubmit="return validate()">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['id'];?>" />
<thead>

<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">Sub Category</div>
        <div style="float:right"><a href="index.php?tc=classifieds_subcategory" class="back">View Sub Category</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Category Name</td>
    <td align="left">
<select name="cat" id="cat" class="txtborder" style="width:220px;">
    <?php 
	
	
$ads=mysql_query("select * from classifieds_category where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?>
    <option <?php if($row['category_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['category']?></option>
    <?php }?>
    </select></td></tr>
<tr>
	<td align="right" width="150">Sub category Name *</td>
    <td align="left"><input type="text" name="name" style="width:200px;" value="<?php echo  $row['sub_cat_name'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="250" valign="top">Description</td>
    <td align="left">
    <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo  stripslashes($row['desc']);?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
   </td>
</tr>
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value="1" checked="checked" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:250px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="saveclassifiedscat" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updateclassifiedscat" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
